#!/bin/bash

# Change to the script directory
# The following DIR line is from
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$DIR"

# Download wxPython
echo "Downloading wxPython..."
DOWNLOAD_URL="hulk.osd.wednet.edu/~baumgardtwellandersr/wx2.8.dmg"
DOWNLOADED_FILE="wx2.8.dmg"
curl -L -O "$DOWNLOAD_URL"

# Extract wxPython
echo "Extracting wxPython..."
MOUNTED_VOLUME="/Volumes/wxPython2.8-osx-unicode-2.8.12.1-universal-py2.6"
PACKAGE_LOCATION="$MOUNTED_VOLUME/wxPython2.8-osx-unicode-universal-py2.6.pkg/Contents/Resources/wxPython2.8-osx-unicode-universal-py2.6.pax.gz"
FOLDER_TO_EXTRACT="./usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.6/site-packages/wx-2.8-mac-unicode"

hdiutil attach "$DOWNLOADED_FILE"
gunzip -c "$PACKAGE_LOCATION" | pax -r -s ",$FOLDER_TO_EXTRACT,./," "$FOLDER_TO_EXTRACT/wx" "$FOLDER_TO_EXTRACT/wxPython"
hdiutil detach "$MOUNTED_VOLUME"
rm "$DOWNLOADED_FILE"

source launch.command